<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="角色名称">
              <a-input placeholder="请输入角色名称" v-model="queryParam.remark8"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="昵称">
              <a-input placeholder="请输入昵称" v-model="queryParam.wxName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="电话号">
              <a-input placeholder="请输入电话号" v-model="queryParam.phone"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="maintain"><a-icon type="form"/>批量维护比赛结果</a-menu-item>

          <a-menu-item key="2" @click="allTicketReturn"><a-icon type="interation"/>批量退票</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-if="record.remark9 == '0'">维护比赛结果</a>

         <a-divider v-if="record.remark10 == '0' && record.remark9 == '0'" type="vertical"/>
            <a-popconfirm v-if="record.remark10 == '0'" title="确定退票吗?" @confirm="() => ticketReturn(record.id)">
                  <a>退票</a>
            </a-popconfirm>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <signUp-modal ref="modalForm" @ok="modalFormOk"></signUp-modal>
    <update-sign-up-modal ref="modalForm1" @ok="modalFormOk"></update-sign-up-modal>
  </a-card>
</template>

<script>
  import '@/assets/less/TableExpand.less'
  import UpdateSignUpModal from './modules/UpdateSignUpModal'
  import SignUpModal from './modules/SignUpModal'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction } from '@/api/manage'
  import { postAction } from '@/api/manage'

  export default {
    name: "SignUpList",
    mixins:[JeecgListMixin],
    components: {
      SignUpModal,UpdateSignUpModal
    },
    data () {
      return {
        description: '用户报名管理管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
           },
          {
            title: '角色名称',
            align:"center",
            dataIndex: 'remark8'
          },
		   {
            title: '昵称',
            align:"center",
            dataIndex: 'wxName'
           },
		   {
            title: '电话号',
            align:"center",
            dataIndex: 'phone'
           },
		   {
            title: '真实姓名',
            align:"center",
            dataIndex: 'realName'
           },
		   {
            title: '身份证号',
            align:"center",
            dataIndex: 'idCard'
           },
          {
            title: '身份',
            align: 'center',
            dataIndex: 'identity_dictText'
          },
          {
            title: '是否点击进入房间',
            align: 'center',
            dataIndex: 'start_dictText'
          },
          {
            title: '比赛结果',
            align: 'center',
            dataIndex: 'result_dictText'
          },
          /*{
            title: '奖励',
            align:"center",
            dataIndex: 'reward'
          },*/
		   /*{
            title: 'matchId',
            align:"center",
            dataIndex: 'matchId'
           },
		   {
            title: 'userId',
            align:"center",
            dataIndex: 'userId'
           },*/
          /*{
            title: '操作',
            dataIndex: 'action',
            align:"center",
            scopedSlots: { customRender: 'action' },
          }*/
        ],
		url: {
          list: "/signup/signUp/list?matchId=" + this.$route.query.matchId,
          delete: "/signup/signUp/delete",
          deleteBatch: "/signup/signUp/deleteBatch",
          exportXlsUrl: "signup/signUp/exportXls",
          importExcelUrl: "signup/signUp/importExcel",
          ticketReturn: '/match/match/ticketReturn',
          allTicketReturn: '/signup/signUp/allTicketReturn',
       },
    }
  },
  computed: {
    importExcelUrl: function(){
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    }
  },
    methods: {
      routeReload(){
        this.reloadFlag = false
        let ToggleMultipage = "ToggleMultipage"
        this.$store.dispatch(ToggleMultipage,false)
        this.$nextTick(()=>{
          this.$store.dispatch(ToggleMultipage,true)
          this.reloadFlag = true
        })
      },

      //维护比赛结果
      handleEdit: function(record) {
        console.log(record)

        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = '编辑'
        this.$refs.modalForm.disableSubmit = false
      },
      maintain: function() {
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          this.$refs.modalForm1.edit(ids)
          this.$refs.modalForm1.title = '编辑'
          this.$refs.modalForm1.disableSubmit = false
        }
      },

      //退票
      ticketReturn: function (id) {
        if(!this.url.ticketReturn){
          this.$message.error("请设置url.ticketReturn属性!")
          return
        }
        console.log(id)
        var that = this;
        getAction(that.url.ticketReturn, {id: id}).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.loadData();
            that.routeReload();
          } else {
            that.$message.warning(res.message);
          }
        });
      },

      allTicketReturn: function () {
        if(!this.url.allTicketReturn){
          this.$message.error("请设置url.allTicketReturn属性!")
          return
        }
        if (this.selectedRowKeys.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys.length; a++) {
            ids += this.selectedRowKeys[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: "确认退票",
            content: "是否退票选中数据?",
            onOk: function () {
              that.loading = true;
              postAction(that.url.allTicketReturn, {ids: ids}).then((res) => {
                if (res.success) {
                  that.$message.success(res.message);
                  that.loadData();
                  this.routeReload();
                  that.onClearSelected();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading = false;
              });
            }
          });
        }
      },

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>